<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">


<p:dialog id="dialogCadastro" modal="true" width="60%" position="top"
	appendTo="@(body)" widgetVar="dialogCadastroAnimal" closable="false"
	header="Cadastro de Animal" resizable="true" draggable="true">
	<p:ajax event="close" listener="#{animalMB.closeAnimal}"
		update="frmDialogAnimal" />

	<h:form id="frmDialogAnimal">

		<h:panelGrid columns="2" style="horizontal-align:center">
			<p:outputLabel value="Codigo:" />
			<p:inputText id="codigo" value="#{animalMB.animalSelecionado.codigo}"
				disabled="true" />

			<p:outputLabel value="Data de Cadastro:" />
			<p:inputMask id="dataCadastro"
				value="#{animalMB.animalSelecionado.dataCadastro}" disabled="true"
				maxlength="10" mask="99/99/9999">
				<f:convertDateTime pattern="dd/MM/yyyy" timeZone="GMT-3" />
			</p:inputMask>

			<p:outputLabel for="nome" value="Nome do Animal:" />
			<p:focus for="nome">
				<p:inputText id="nome"
					value="#{animalMB.animalSelecionado.nomeAnimal}"
					disabled="#{not animalMB.incluindo}" required="true" maxlength="50"
					 style="width:270px" requiredMessage="Nome do Animal é obrigatório!" />
			</p:focus>

			<p:outputLabel value="Tipo Animal:" for="selecttipo"></p:outputLabel>
			<p:selectOneMenu value="#{animalMB.animalSelecionado.tipoAnimal}"
				required="true" id="selecttipo" style="width:270px"
				rendered="#{animalMB.incluindo}"
				disabled="#{not animalMB.incluindo}" converter="tipoAnimalConverter">
				<f:selectItem itemLabel="" itemValue="#{null}"></f:selectItem>
				<f:selectItems value="#{animalMB.listaTipoAnimal}" var="tipo"
					itemLabel="#{tipo.descricao}" itemValue="#{tipo}"></f:selectItems>
				<p:ajax event="change" listener="#{animalMB.preencheRaca}"
					update="selectraca"></p:ajax>
			</p:selectOneMenu>
			<p:inputText rendered="#{not animalMB.incluindo}" disabled="true"
				value="#{animalMB.animalSelecionado.tipoAnimal.descricao}"
				style="width:270px"></p:inputText>

			<p:outputLabel value="Raça:" for="selectraca"></p:outputLabel>
			<p:selectOneMenu value="#{animalMB.animalSelecionado.raca}"
				rendered="#{animalMB.incluindo}" required="true" id="selectraca"
				style="width:270px" disabled="#{not animalMB.incluindo}"
				converter="racaConverter">
				<f:selectItems value="#{animalMB.listaRaca}" var="raca"
					itemLabel="#{raca.descricao}" itemValue="#{raca}"></f:selectItems>
			</p:selectOneMenu>
			<p:inputText style="width:270px" rendered="#{not animalMB.incluindo}"
				value="#{animalMB.animalSelecionado.raca.descricao}" disabled="true"></p:inputText>

			<p:outputLabel value="Pelagem/Cor:" for="iptcor"></p:outputLabel>
			<p:inputText id="iptcor" value="#{animalMB.animalSelecionado.cor}"
				 style="width:270px" required="true"
				requiredMessage="Pelagem/Cor é obrigatória" maxlength="50"
				disabled="#{animalMB.consultando}"></p:inputText>

			<p:outputLabel value="Sexo:" for="genero"></p:outputLabel>
			<p:selectOneRadio id="genero" disabled="#{animalMB.consultando}"
				value="#{animalMB.animalSelecionado.generoAnimal}">
				<f:selectItems var="genero" value="#{animalMB.listaGenero}"
					itemLabel="#{genero.descricao}" itemValue="#{genero}"></f:selectItems>
			</p:selectOneRadio>

			<p:outputLabel value="Data de Nascimento:" for="dataNasc" />
			<p:inputMask value="#{animalMB.animalSelecionado.dataNascimento}"
				disabled="#{animalMB.consultando}" required="true" maxlength="8"
				requiredMessage="Data de Nascimento é obrigatória!" id="dataNasc"
				mask="99/99/9999">
				<f:convertDateTime pattern="dd/MM/yyyy" timeZone="GMT-3" />
			</p:inputMask>

			<p:outputLabel for="idade" value="Idade:" />
			<p:focus for="idade">
				<p:inputText id="idade" value="#{animalMB.animalSelecionado.idade}"
					disabled="true"  style="width:270px"/>
			</p:focus>


			<p:outputLabel value="Observações:"></p:outputLabel>
			<p:inputTextarea id="obs"
				value="#{animalMB.animalSelecionado.observacao}" style="width:270px"
				disabled="#{animalMB.consultando}" maxlength="150"></p:inputTextarea>

		</h:panelGrid>
		<h:panelGrid columns="2">
			<p:commandButton value="Confirma" actionListener="#{animalMB.salvar}"
				rendered="#{not animalMB.consultando}"
				update=":mensagem,:frmTab:tabela"
				oncomplete="validaDialog(args,'dialogCadastroAnimal','frmDialogAnimal:dialogCadastro')" />


			<p:commandButton id="btnFechar" value="Cancela"
				onclick="dialogCadastroAnimal.hide()" immediate="true" />
		</h:panelGrid>
	</h:form>
</p:dialog>

</html>